package domain.model.project.support.projectid;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import domain.model.project.ProjectId;

/**
 * @author Gregory Boissinot
 */
@JsonSerialize(using = ProjectIdSerializer.class)
public class ProjectIdImpl implements ProjectId {

    private final String organization;
    private final String name;

    public ProjectIdImpl(String organization, String name) {
        this.organization = organization;
        this.name = name;
    }

    @Override
    public String getOrganization() {
        return organization;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public String toString() {
        return "{" +
                "org='" + organization + '\'' +
                ", name='" + name + '\'' +
                '}';
    }

    @Override
    public boolean sameValueAs(ProjectId objectValue) {
        return equals(objectValue);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        ProjectIdImpl projectId = (ProjectIdImpl) o;

        if (name != null ? !name.equals(projectId.name) : projectId.name != null) return false;
        if (organization != null ? !organization.equals(projectId.organization) : projectId.organization != null)
            return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = organization != null ? organization.hashCode() : 0;
        result = 31 * result + (name != null ? name.hashCode() : 0);
        return result;
    }
}

